﻿using System;
using Autodesk.Revit.UI;
using YJKRevitBase.WinForm;

namespace YJKInspectModel.ModelValidation.AdjoinFireZone
{
	public class AdjoinFireZoneHorApplication : IExternalApplication
	{
		public Result OnShutdown(UIControlledApplication application)
		{
			if (AdjoinFireZoneHorApplication.m_formViewNotFit != null && AdjoinFireZoneHorApplication.m_formViewNotFit.Visible)
			{
				AdjoinFireZoneHorApplication.m_formViewNotFit.Close();
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public Result OnStartup(UIControlledApplication application)
		{
			AdjoinFireZoneHorApplication.m_formViewNotFit = null;
			AdjoinFireZoneHorApplication.thisApp = this;
			return Autodesk.Revit.UI.Result.Succeeded;
		}

        public void ShowForm(ExternalCommandData commandData, WindowHandle _hWndRevit, AdjoinFireZoneCheck checkManage)
		{
			if (AdjoinFireZoneHorApplication.m_formViewNotFit == null || AdjoinFireZoneHorApplication.m_formViewNotFit.IsDisposed)
			{
				AdjoinFireZoneHandler adjoinFireZoneHandler = new AdjoinFireZoneHandler();
				ExternalEvent exEvent = ExternalEvent.Create(adjoinFireZoneHandler);
				AdjoinFireZoneHorApplication.m_formViewNotFit = new ViewNotFitWinListForm(commandData, _hWndRevit, adjoinFireZoneHandler, exEvent, checkManage);
			}
			if (!AdjoinFireZoneHorApplication.m_formViewNotFit.CheckTolInfo())
			{
				AdjoinFireZoneHorApplication.m_formViewNotFit = null;
				return;
			}
			AdjoinFireZoneHorApplication.m_formViewNotFit.Show(_hWndRevit);
		}

		public void WakeFormUp()
		{
			if (AdjoinFireZoneHorApplication.m_formViewNotFit != null)
			{
				AdjoinFireZoneHorApplication.m_formViewNotFit.WakeUp();
			}
		}

		public static AdjoinFireZoneHorApplication thisApp;

		public static ViewNotFitWinListForm m_formViewNotFit;
	}
}
